﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Entities;
using Unity.Collections;
using Unity.Transforms;
using Unity.Rendering;
using Unity.Mathematics;

public class Testing : MonoBehaviour
{
    [SerializeField]
    private Mesh m_Mesh;
    [SerializeField]
    private Material m_Material;


    private EntityManager m_Entitymanager;


    // Start is called before the first frame update
    void Start()
    {
        m_Entitymanager = World.DefaultGameObjectInjectionWorld.EntityManager;
        EntityArchetype archetype = m_Entitymanager.CreateArchetype(
            typeof(LevelComponent),
            typeof(Translation),
            typeof(RenderMesh),
            typeof(RenderBounds),
            typeof(LocalToWorld),
            typeof(SpeedComponent)
        );

        NativeArray<Entity> entityArray = new NativeArray<Entity>(100000, Allocator.Temp);

        m_Entitymanager.CreateEntity(archetype, entityArray);

        for(int i = 0; i < entityArray.Length; i++)
        {
            m_Entitymanager.SetComponentData<LevelComponent>(entityArray[i], new LevelComponent() 
            { 
                level = UnityEngine.Random.Range(0, 200) 
            });

            m_Entitymanager.SetComponentData<SpeedComponent>(entityArray[i], new SpeedComponent()
            {
                Speed = UnityEngine.Random.Range(4, 20)
            });

            m_Entitymanager.SetComponentData<Translation>(entityArray[i], new Translation()
            {
                Value = new float3(UnityEngine.Random.Range(-10, 10), UnityEngine.Random.Range(-10, 10), UnityEngine.Random.Range(-10, 10))
            }); ;

            m_Entitymanager.SetSharedComponentData<RenderMesh>(entityArray[i], new RenderMesh() 
            { 
                mesh = m_Mesh,
                material = m_Material
            }) ;
        }

        entityArray.Dispose();        

    }


}
